package org.developer.es.controller;

import lombok.extern.slf4j.Slf4j;
import org.developer.es.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/rest")
public class RestHighClientController {

    @Autowired
    private DemoService demoService;

    /**
     * 参考链接：https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-index.html
     * @throws IOException
     */
    @GetMapping("/index")
    public void index() throws IOException {

        demoService.index();
    }

    /**
     * 参考链接：https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-get.html#java-rest-high-document-get-sync
     * @return
     * @throws IOException
     */
    @GetMapping("/get")
    public String get() throws IOException {

        return demoService.fetch();
    }

    @GetMapping("/search")
    public String search() throws IOException {

        return demoService.search();
    }
}
